<template>
	<view>
		<view class="" v-for="(item,index) in schoolList" :key="index">
			<view class="switch-container" @click="schoolSwitch(item)">
				<view class="sc-left">
					<img :src="item.schoolLogo" alt="" style="border-radius: 50%; width: 100%;height: 100%;" />
				</view>
				<view class="sc-right">
					<view class="cr-name">{{item.name}}</view>
					<view class="cr-address">{{item.address}}</view>
				</view>
			</view>
			<view class="space"></view>
		</view>

	</view>
</template>

<script>
	import {
		getSchoolList,
		schoolSwitch
	} from '@/utils/api.js'
	export default {
		data() {
			return {
				schoolList: []
			}
		},
		onLoad() {
			this.getSchoolList()
		},
		methods: {
			async getSchoolList() {
				uni.showLoading()
				const data = {
					appid: uni.getStorageSync('appId')
				}
				const res = await getSchoolList(data)
				if (res.code == 200) {
					this.schoolList = res.data
					uni.hideLoading()
				}
			},
			async schoolSwitch(item) {
				uni.showLoading()
				const data = {
					schoolId: item.id
				}
				const res = await schoolSwitch(data)
				if (res.code == 200) {
					uni.hideLoading()
					uni.setStorageSync('token', res.data.token)
					uni.reLaunch({
						url: '/pages/index/index'
					})
				}
			}
		}
	}
</script>

<style>
	.switch-container {
		display: flex;
		padding: 40rpx 20rpx;

	}

	.sc-left {
		width: 100rpx;
		height: 100rpx;
	}

	.sc-right {
		margin-left: 20rpx;
		margin-top: 10rpx;
	}

	.cr-name {
		font-weight: bold;
	}

	.cr-address {
		color: #827f7f;
		margin-top: 10rpx;
	}

	.space {
		width: 95%;
		height: 2rpx;
		background-color: #ebe6e6;
		margin: 0 auto;
	}
</style>